package com.briup.day38;

import static org.junit.Assert.*;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import org.junit.Test;

/**
 * 对象流
 * */
public class IODemo6 {
	
	public static void main(String[] args) {
		
	}
	
	@Test
	public void write() throws Exception {
		
		Student student = new Student(1001, "tom", 22, "男");
		
		String path = "src/com/briup/day38/demo6.txt";
		FileOutputStream fos = new FileOutputStream(path);
		
		ObjectOutputStream oos = new ObjectOutputStream(fos);
		
		oos.writeObject(student);
		
		if (oos != null) {
			oos.close();
		}
		
		System.out.println("Successful!");
	}
	
	@Test
	public void read() throws Exception {
		
		String path = "src/com/briup/day38/demo6.txt";
		FileInputStream fis = new FileInputStream(path);
		ObjectInputStream ois = new ObjectInputStream(fis);
		
		Student student = (Student) ois.readObject();
		System.out.println(student);
		
		student.setAge(26);
		System.out.println(student);
		
		ois.close();
	}

}
